<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Menu;
use App\Models\Role;
use App\Models\Access;

class BaseController extends Controller{

	public $gadmin;
	// 构造函数
	public function __construct(Request $request)
	{
		$currentaction=\Route::currentRouteAction();

		$pbread=collect();

		$this->gadmin = \Auth::user();
		$routeinfo=Menu::where('action',$currentaction)->first();

      

		$menu = Menu::join('access','menu.id','=','access.menu_id')->where('access.role_id',$this->gadmin->role_id)->where('menu.pid',1)->where('menu.status_at',1)->orderBy('menu.sort', 'asc')->get();

         

		foreach ($menu as $item) {
            $item['submenu'] = Menu::join('access','menu.id','=','access.menu_id')->where('access.role_id',$this->gadmin->role_id)->where('menu.pid',$item->id)->where('menu.status_at',1)->orderBy('menu.sort', 'asc')->get();
        }
        if($routeinfo){
        	$pbread=Menu::where('status_at',1)->where('id',$routeinfo->pid)->select('id','name','uri')->first();
        }

        // dd($pbread);

        // dd($menu->toArray());
        view()->share('gadmin', $this->gadmin);
        view()->share('menu', $menu);
        view()->share('routeinfo', $routeinfo);
        view()->share('pbread', $pbread);
	}	
}

